from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render

# Create your views here.
from django.http.response import HttpResponse, JsonResponse

from django.views import View


def set_session(request):
    username = request.GET.get("username")

    request.session['username'] = username

    request.session.set_expiry(3600)

    return HttpResponse('set_session')


def get_session(requset):
    username = requset.session.get('username')
    print(username)

    return HttpResponse(username)


def index(request):
    if request.method == 'GET':
        return HttpResponse('get')

    else:
        return HttpResponse('其他')


class JdView(View):
    def get(self,request):
        return HttpResponse('get')

    def post(self,request):
        return HttpResponse('post')


#LoginRequiredMixin
# CenterView.__mro__查看多继承的执行顺序
class CenterView(LoginRequiredMixin, View):

    def get(self,request):
        # is_login = False
        #
        # if is_login:
            return HttpResponse('login.html')
        # else:
        #     return HttpResponse('notlogin')

    def post(self,request):

        return HttpResponse('post')